<!DOCTYPE html>
<html>
  <!-- Html Head Tag-->
  <head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="Rms">
  <!-- Open Graph Data -->
  <meta property="og:title" content="Linux安装jdk"/>
  <meta property="og:description" content="" />
  <meta property="og:site_name" content="帅的一逼"/>
  <meta property="og:type" content="article" />
  <meta property="og:image" content="http://shsa.gitee.io"/>
  
    <link rel="alternate" href="/atom.xml" title="帅的一逼" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  

  <!-- Site Title -->
  <title>帅的一逼</title>

  <!-- Bootstrap CSS -->
  
<link rel="stylesheet" href="/myblog/css/bootstrap.min.css">

  <!-- Custom CSS -->
  
  
<link rel="stylesheet" href="/myblog/css/style.light.css">


  <!-- Google Analytics -->
  

<meta name="generator" content="Hexo 4.2.1"></head>

  <body>
    <!-- Page Header -->


<header class="site-header header-background" style="background-image: url(/myblog//img/i.jpg)">
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <div class="page-title with-background-image">
          <p class="title">Linux安装jdk</p>
          <p class="subtitle"></p>
        </div>
        <div class="site-menu with-background-image">
          <ul>
            
              <li>
                <a href="/myblog/">
                  
                  Home
                  
                </a>
              </li>
            
              <li>
                <a href="/myblog/archives">
                  
                  Archives
                  
                </a>
              </li>
            
              <li>
                <a href="/myblog/about">
                  
                  About
                  
                </a>
              </li>
            
          </ul>
        </div>
      </div>
    </div>
  </div>
</header>

<article>
  <div class="container typo">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <div class="post-info text-muted">
          
            <!-- Author -->
            <span class="author info">By Rms</span>
          
          <!-- Date -->
          <span class="date-time info">On
            <span class="date">2020-07-16</span>
            <span class="time">21:53:53</span>
          </span>
          
        </div>
        <!-- Tags -->
        
        <!-- Post Main Content -->
        <div class="post-content">
          <h1 id="Linux安装jdk"><a href="#Linux安装jdk" class="headerlink" title="Linux安装jdk"></a>Linux安装jdk</h1><p>使用root账号操作,切换root账号命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">su root</span><br></pre></td></tr></table></figure>

<p>然后输入密码，linux输入密码没有显示，放心输入</p>
<p>1.查询linux有没有自带jdk</p>
<p>使用下方命令查询自带jdk</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep jdk</span><br></pre></td></tr></table></figure>

<img src="https://pic.baixiongz.com/2020/07/16/5d37cd7ed0c4e.png" alt="image.png" style="zoom:50%;" />

<p>如果查出jdk则使用下面命令移除默认jdk</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum -y remove &lt;对应的jdk名字&gt;</span><br><span class="line">//如上图为</span><br><span class="line">yum -y remove java-1.5.0-gcj-devel-1.5.0.0-29.1.el6.x86_64</span><br></pre></td></tr></table></figure>

<p>2.下载jdk</p>
<p>卸载完成后，用wget命令从oracle下载jdk(注意:需要oracle账号才能下载)</p>
<p>跳转/usr/local路径(需要注意自己的下载路径，一般默认装/usr/local路径下)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd /usr/local</span><br></pre></td></tr></table></figure>

<p>下载地址:<a href="https://www.oracle.com/java/technologies/javase-downloads.html" target="_blank" rel="noopener">https://www.oracle.com/java/technologies/javase-downloads.html</a></p>
<p>使用浏览器复制jdk下载链接，然后使用wget在CentOS下载</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget https://download.oracle.com/otn/java/jdk/8u261-b12/a4634525489241b9a9e1aa73d9e118e6/jdk-8u261-linux-x64.tar.gz?AuthParam=1594808307_5719cb7d3245f1a688231523f6f15704</span><br></pre></td></tr></table></figure>

<p>3.安装jdk</p>
<p>使用ls命令查看local目录下的所有文件，会看到刚刚下的的jdk包</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls</span><br></pre></td></tr></table></figure>

<p>名字过长，可以使用如下命令改名</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv jdk-8u261-linux-x64.tar.gz?AuthParam=1594808307_5719cb7d3245f1a688231523f6f15704 jdk1.8.0_261</span><br></pre></td></tr></table></figure>

<p>创建java文件夹</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir java</span><br></pre></td></tr></table></figure>

<p>然后使用 tar命令解压到/usr/local/java路径下</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf jdk1.8.0_261 -C /usr/local/java/</span><br></pre></td></tr></table></figure>

<p>4.配置jdk环境</p>
<p>使用vim /etc/profile 命令编辑/etc/profile文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/profile</span><br><span class="line">//部分linux没有安装vim命令，可以使用vi命令编辑</span><br><span class="line">vi /etc/profile</span><br></pre></td></tr></table></figure>

<p>在profile末尾加入如下三行(按i进入编辑模式)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">//  /usr/local/java/jdk1.8.0_261是你的jdk安装路径</span><br><span class="line">export JAVA_HOME=/usr/local/java/jdk1.8.0_261</span><br><span class="line">export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/</span><br><span class="line">export PATH=$PATH:$JAVA_HOME/bin</span><br></pre></td></tr></table></figure>

<p>然后按esc输入:wq（冒号算在内）保存并退出</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:wq</span><br></pre></td></tr></table></figure>

<p>然后使用source /etc/profile命令让环境生效，貌似这种方法每打开一次窗口都要重新source /etc/profile</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source /etc/profile</span><br></pre></td></tr></table></figure>

<p>如果想要永久生效就需要添加在/etc/bashrc中，和上面步骤一样，只是把/etc/profile换成/etc/bashrc</p>
<p>5.测试是否安装成功</p>
<p>输入java，如果出现下图所示，则代表jdk安装成功</p>
<img src="https://pic.baixiongz.com/2020/07/16/d46ee21e3431a.png" alt="image.png" style="zoom: 80%;" />

<p>输入javac，如果出现下图所示，则代表jdk环境配置成功</p>
<img src="https://pic.baixiongz.com/2020/07/16/b263d4c16d734.png" alt="image.png" style="zoom: 67%;" />



<p>本文转载:<a href="https://all_jun.gitee.io/blog/2020/07/15/CentOS安装jdk/" target="_blank" rel="noopener">https://all_jun.gitee.io/blog/2020/07/15/CentOS%E5%AE%89%E8%A3%85jdk/</a></p>

        </div>
      </div>
    </div>
  </div>
</article>



    <!-- Footer -->
<footer>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <p class="copyright text-muted">
          Theme By <a target="_blank" href="https://github.com/levblanc">Levblanc.</a>
          Inspired By <a target="_blank" href="https://github.com/klugjo/hexo-theme-clean-blog">Clean Blog.</a>
        <p class="copyright text-muted">
          Powered By <a target="_blank" href="https://hexo.io/">Hexo.</a>
        </p>
      </div>
    </div>
  </div>
</footer>


    <!-- After Footer Scripts -->

<script src="/myblog/js/highlight.pack.js"></script>

<script>
  document.addEventListener("DOMContentLoaded", function(event) {
    var codeBlocks = Array.prototype.slice.call(document.getElementsByTagName('pre'))
    codeBlocks.forEach(function(block, index) {
      hljs.highlightBlock(block);
    });
  });
</script>

  </body>
</html>

